/**
 * Created by lwy on 2017/8/1.
 */


var page = 1;
var id;
var type = 0,
    year = 2017,
    month = '';

function doAjax(){
    $.ajax({
        url:'/crm/agentSalaryC/search.json',
        dataType:'json',
        data:{
            token:localStorage.getItem('crmtoken'),
            pageNu:page,
            type:type,
            year:year,
            month:month,
        },
        type:'post',
        success: function (data) {
            if(data.code==-1){
                window.parent.location.href="/crm/login.jsp"
            }
            if(data.code==0){
                alert(data.msg);
            }
            if(data.code==1){
                $('#record').html(data.datas.recordsTotal);
                $('#withdraw-record').empty();
                for(var i=0;i<data.datas.agentList.length;i++){
                    var userType = '';
                    var ifAccount = '';
                    if(data.datas.agentList[i].type==1){
                        userType = '代理'
                    }else{
                        userType = '业务员';
                    }
                    if(data.datas.agentList[i].settlement){
                        ifAccount = '是'
                    }else{
                        ifAccount = '否';
                    }
                    $('<tr class="gradeA odd">'+
                        '<a href=""><td class="sorting_1 withdrawId" style="text-decoration: underline;cursor: pointer;" data-toggle="modal" data-target="#myModal4" id="'+data.datas.agentList[i].id+'">'+data.datas.agentList[i].id+'</td></a>'+
                        '<td class=" ">'+data.datas.agentList[i].name+'</td>'+
                        '<td class=" ">'+data.datas.agentList[i].realName+'</td>'+
                        '<td class="center ">'+userType+'</td>'+
                        '<td class="sorting_1">'+data.datas.agentList[i].year+'</td>'+
                        '<td class="sorting_1">'+data.datas.agentList[i].month+'</td>'+
                        '<td class=" ">'+data.datas.agentList[i].agentName+'</td>'+
                        '<td class=" ">'+data.datas.agentList[i].agentRealName+'</td>'+
                        '<td class="sorting_1">'+data.datas.agentList[i].earning+'</td>'+
                        '<td class="sorting_1">'+ifAccount+'</td>'+
                        '</tr>').appendTo($('#withdraw-record'));
                }


                $(".pagination").createPage({
                    totalPage:data.datas.totalPage,
                    currPage:data.datas.pageNu,
                    pageCount:data.datas.pageNu,
                    turndown:'true',
                    backFn:function(p){
                        page=p;
                        doAjax();
                    }
                });
            }
        }
    })
}

$(function(){
    doAjax();
})



//查询
$('#refer').click(function(){
    page=1;
    type = $('#type').val();
    year = $('#year').val();
    month = $('#month').val();
    doAjax();
})


